package com.autonavi.yunda.yunji.core.config;

import com.autonavi.yunda.yunji.core.enums.Env;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author cizhong.wcs
 * @date 2022/7/1 10:34
 */
@Component
public class ApplicationEnvConfig {
    @Value("${spring.profiles.active}")
    private String activeProfile;

    public boolean isDev() {
        return "dev".equalsIgnoreCase(activeProfile);
    }

    public boolean isDaily() {
        return Env.daily.getCode().equalsIgnoreCase(activeProfile);
    }

    public boolean isPublish() {
        return activeProfile.startsWith(Env.publish.getCode());
    }

    public boolean isPrepub() {
        return activeProfile.startsWith(Env.prepub.getCode());
    }

    /**
     * 不返回dev环境,dev环境看做daily
     *
     * @return daily publish prepub
     */
    public Env getEnv() {
        if (isPublish()) {
            return Env.publish;
        } else if (isPrepub()) {
            return Env.prepub;
        }
        return Env.daily;
    }
}
